package cn.luoshaocheng.pet.service.impl;

import cn.luoshaocheng.basic.service.impl.BaseServiceImpl;
import cn.luoshaocheng.org.domain.Department;
import cn.luoshaocheng.org.mapper.DepartmentMapper;
import cn.luoshaocheng.org.service.IDepartmentService;
import cn.luoshaocheng.pet.domain.Pet;
import cn.luoshaocheng.pet.domain.PetDetail;
import cn.luoshaocheng.pet.mapper.PetDetailMapper;
import cn.luoshaocheng.pet.mapper.PetMapper;
import cn.luoshaocheng.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
//只读，事务传播机制=SUPPORTS，有我就用，没有事务就不用
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {
    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;
    @Override
    public void save(Pet pet) {
        // 先添加pet，返回自增的主键
        petMapper.save(pet);
        // 再添加pet_datail
        PetDetail petDetail = pet.getPetDetail();
        petDetail.setPet_id(pet.getId());
        petDetailMapper.save(petDetail);
    }

    @Override
    public void update(Pet pet) {
        petMapper.update(pet);
        petDetailMapper.update(pet.getPetDetail());
    }



    @Override
    public void onsale(List<Long> ids) {
        Date date = new Date();
        petMapper.onsale(ids,date);
    }

    @Override
    public void offsale(List<Long> ids) {
        Date date = new Date();
        petMapper.offsale(ids,date);
    }
}

